'use strict';
/**
 * @Controller login
 */
const Controller = require('egg').Controller;

class LoginController extends Controller {
  /**
   * @summary 登录
   * @description 登录
   * @router post ppyy/login
   * @request query string *email id
   * @request query string *password 密码
   * @response 200 JsonResult 操作结果
   */
  async login() {
    const { ctx, service } = this;
    let { email, password } = ctx.request.body;
    // console.log('req', email, password)
    // 调取服务
    let resObj = await service.post.postLogin({ email, password });
    
    ctx.body = resObj;
  }

  /**
    * @summary 注册
    * @description 注册
    * @router post ppyy/register
    * @request query string *email ID
    * @request query string *qq
    * @request query string *reg 验证码
    * @request query string *password1
    * @request query string *password2
    * @request query string userName
    * @response 200 JsonResult 操作结果
    */
  async register() {
    const { ctx, service } = this;
    // 获取post 参数
    let { email, qq, password1, password2, userName } = ctx.request.body;
    let err600 = await service.error.code600();
    if (!email || email == '') return ctx.body = err600;
    if (!qq || qq == '') return ctx.body = err600;
    if (!password1 || password1 == '') return ctx.body = err600;
    if (!password2 || password2 == '') return ctx.body = err600;

    // 调取服务
    let resObj = await service.post.postRegister({ email, qq, password1, password2, userName });

    ctx.body = resObj;
  }

  /**
   * @summary 找回密码
   * @description 找回密码
   * @router post ppyy/forgetPassword
   * @request query string Id ID
   * @response 200 JsonResult 操作结果
   */
  async forgetPassword() {
    const { ctx } = this;
    ctx.body = '找回密码';
  }

}

module.exports = LoginController;
